#include "stdafx.h"

FrameAnimation::FrameAnimation(int x, int y)
{
	this->x = x;
	this->y = y;
}

FrameAnimation::~FrameAnimation()
{
}

bool FrameAnimation::update(double dtime)
{
	time += dtime;
	if (time > (currentFrame + 1)*interval)
	{
		currentFrame++;
		if (currentFrame < count)
		{
			currentImage = ImageMgr::getInstance()->get(foldername + "/" + std::to_string(currentFrame) + ".png");
		}
		else
		{
			return false;
		}
	}

	return true;
}

bool FrameAnimation::render()
{
	return currentImage->render(getDisplayX(), getDisplayY(), 0);
}

void FrameAnimation::setFolder(const std::string & foldername)
{
	this->foldername = foldername;

	currentImage = ImageMgr::getInstance()->get(foldername + "/0.png");
}

void FrameAnimation::setCount(int cnt)
{
	count = cnt;
}

void FrameAnimation::setInterval(double interval)
{
	this->interval = interval;
}

void FrameAnimation::setMap(Map * map)
{
	this->map = map;
}